<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312" session="true"%>
<%@ page import="beans.*" %>
<%@ page import="java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>

<body>
<jsp:useBean id="activeUser" class="beans.UserBean" scope="session" />
<center><font size= "4">
<%
	String username = activeUser.getUsername();
	String loginCmd = (String)session.getAttribute("loginCmd");
	if(username == null || loginCmd ==null) out.println("Error!");
	else{
		String []part={"CRE VM:TID=",",VMNAME="};
		CommanderBean commander = new CommanderBean();
		String reply = commander.sendCommand(loginCmd);
		int pos = reply.indexOf('=')+1;
		if(reply.charAt(pos)=='0'){
		
			String vmName = request.getParameter("VMname");
			String system = request.getParameter("system");
			String TID = system.substring(0,system.indexOf(' '));
			String createVMCmd = new String(part[0]+TID+part[1]+username+"_"+vmName);
			reply = commander.sendCommand(createVMCmd);
			pos = reply.indexOf('=')+1;
			if(reply.charAt(pos)=='0'){
%>
				<jsp:forward page="onSuccess.jsp"/>
<%				commander.close();
			
			} else {
				out.println("VM creation failed!");
%>
				<a href="listVMs.jsp">Go Back To the VM list</a>
				<a href="addVM.jsp">Add a new VM</a>
				<a href="logout.jsp">Logout</a>
<% 				commander.close();
			}
		} else {
			out.println("VM creation failed!");
%>
			<a href="listVMs.jsp">Go Back To the VM list</a>
			<a href="addVM.jsp">Add a new VM</a>
			<a href="logout.jsp">Logout</a>
<%			commander.close();
		}
	}
%>
</font></center>
</body></html>